package Server.ExtComponents.socket;



import Server.ExtComponents.BaseConfig.MServerConfig;
import Server.ServerCore.Service.DataPacks.packRespose.disConnect_response;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.timeout.IdleState;
import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler;
import org.jboss.netty.handler.timeout.IdleStateEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public final class MServerFrameIdleStateCheckHandler extends IdleStateAwareChannelHandler {
    private static final Logger LOG = LoggerFactory.getLogger(MServerFrameIdleStateCheckHandler.class);

    @Override
    public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
        Channel c=e.getChannel();
        if (e.getState() ==IdleState.READER_IDLE){
            if(MServerConfig.NETTY_DEBUG)LOG.info(c.getRemoteAddress()+"--READER_IDLE TIMEOUT");
            //超时信息通知 4，2
            disConnect_response disConnectResponse=new disConnect_response();
            ctx.getChannel().write(disConnectResponse.getJsonData(4,2));
            c.close();
        }else if(e.getState() ==IdleState.WRITER_IDLE){
            if(MServerConfig.NETTY_DEBUG)LOG.info(c.getRemoteAddress()+"--WRITER_IDLE TIMEOUT");
            c.close();
        }
    }
}
